<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/12/3
 * Time: 14:59
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\lib\Show;
use app\common\lib\Status;
use think\Exception;

class Comment extends Base
{
    public function setComment()
    {
        $openid = $this->request->param('openid', '', 'trim');
        $msg = $this->request->param('msg', '', 'trim');
        $id = $this->request->param('id', 0, 'intval');
        $type = $this->request->param('type',1,'intval');
        $msg = stripslashes($msg);
        $data = [
            "theatre_id" => $id,
            "msg" => $msg,
            "openid" => $openid,
            "type"=>$type
        ];
        try {
            $res = (new \app\common\business\Comment())->add($data);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        if ($res) {
            return Show::json_show(Status::mini_normal, "ok");
        } else {
            return Show::json_show(Status::mini_error, "评论失败");
        }
    }

    public function getCommentList()
    {
        $openid = $this->request->param('openid', '', 'trim');

        $id = $this->request->param('id', 0, 'intval');
        $type = $this->request->param('type',1,'intval');
        try {
            $lists = (new \app\common\business\Comment())->getCommentList($id, $openid,$type);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        return Show::json_show(Status::mini_normal, 'ok', $lists);
    }
}